var i;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var BundleConfig = require("AA_BundleConfig");
var AudioManager = require("AA_AudioManager");
var EventManager = require("AA_EventManager");
var UIManager = require("AA_UIManager");
var UIView = require("AA_UIView");
var CommonUtils = require("AA_CommonUtils");
var EvenType = require("AA_EvenType");
var Excel = require("AA_Excel");
var UIConfig_Home = require("AA_UIConfig_Home");
var BuffMag = require("AA_BuffMag");
var _decorator = cc._decorator;
var _ccclass = _decorator.ccclass;
var _property = _decorator.property;

var _def_UI_GamePuase = function (e) {
  function _creator() {
    var t = null !== e && e.apply(this, arguments) || this;
    t.tipView = null;
    t.scroll = null;
    t.tipUi = null;
    t.nowBack = null;
    t.endindex = -1;
    return t;
  }
  __extends(_creator, e);
  _creator.prototype._show = function (e) {
    var t = [];
    for (var o = 1; o < arguments.length; o++) {
      t[o - 1] = arguments[o];
    }
    this.nowBack = e.back;
    this.tipView.active = false;
    EventManager.EventMgr.dispatchEvent(EvenType.EVENT_TYPE.GAME_HIDE_CLICK);
  };
  _creator.prototype.onEnable = function () {
    this.tipUi.active = false;
    this.initUi();
    CommonUtils.default.cleanGold();
  };
  _creator.prototype.initUi = function () {
    return __awaiter(this, undefined, undefined, function () {
      var e;
      var t;
      var o;
      var n;
      var i;
      var a;
      var r;
      var c;
      var l;
      var d;
      var p;
      var h;
      var f;
      var g;
      var m;
      var v;
      var b;
      return __generator(this, function (s) {
        switch (s.label) {
          case 0:
            e = BuffMag.BuffMgr.ciTiaoData;
            t = {};
            for (c = 0; c < e.length; c++) {
              o = e[c];
              n = t[o.id];
              if (!n) {
                n = {
                  id: o.id
                };
              }
              i = n.count;
              if (!i) {
                i = 0;
              }
              i += 1;
              n.count = i;
              t[o.id] = n;
            }
            a = Object.keys(t);
            (r = this.scroll.content.children).forEach(function (e) {
              e.active = false;
            });
            c = 0;
            s.label = 1;
          case 1:
            if (c < a.length) {
              l = a[c];
              d = t[l];
              if (!(p = r[c])) {
                p = cc.instantiate(r[0]);
                this.scroll.content.addChild(p);
              }
              p.active = true;
              h = p.children[1].getComponent(cc.Sprite);
              f = p.children[0].getComponent(cc.Sprite);
              g = p.children[2].getComponent(cc.Label);
              m = Excel.Excel.shuiguocitiao(d.id);
              return [4, this._loadRes(BundleConfig.BundleNames.Game, "game/" + "res/skill_icon" + m.quality, cc.SpriteFrame)];
            } else {
              return [3, 5];
            }
          case 2:
            v = s.sent();
            f.spriteFrame = v;
            return [4, this._loadRes(BundleConfig.BundleNames.Common, "common/" + "res/skillicon/skill_" + d.id, cc.SpriteFrame)];
          case 3:
            b = s.sent();
            h.spriteFrame = b;
            g.string = "×" + d.count;
            p.on(cc.Node.EventType.TOUCH_START, this.onClickItem.bind(this, c, d), this);
            s.label = 4;
          case 4:
            c++;
            return [3, 1];
          case 5:
            return [2];
        }
      });
    });
  };
  _creator.prototype.onClickItem = function (e, t) {
    AudioManager.AudioMgr.playEffect("audio/effect/button");
    if (this.endindex != e) {
      this.tipUi.active = true;
      this.endindex = e;
      var o = this.scroll.content.children[e].convertToWorldSpaceAR(cc.v2(0, 0));
      o = this.node.convertToNodeSpaceAR(o);
      this.tipUi.y = o.y + 100;
      this.tipUi.x = o.x;
      var n = -(this.tipUi.x + cc.winSize.width / 2);
      var i = this.tipUi.x + cc.winSize.width / 2;
      n < cc.winSize.width / 2 && (this.tipUi.x = -(cc.winSize.width / 2 - this.tipUi.width / 2));
      i > cc.winSize.width / 2 && (this.tipUi.x = cc.winSize.width / 2 - this.tipUi.width / 2);
      this.tipUi.getChildByName("jiantou").x = o.x - this.tipUi.x;
      var a = Excel.Excel.shuiguocitiao(t.id);
      var r = this.tipUi.getChildByName("lb").getComponent(cc.RichText);
      var c = this.tipUi.getChildByName("layout").getChildByName("count").getComponent(cc.Label);
      var s = Excel.Excel.shuiguobuff(a.citiaoshuzhitype);
      if (-1 != a.citiaochuxian) {
        this.tipUi.getChildByName("layout").active = true;
        c.string = t.count * s.value[0] + "%";
      } else {
        this.tipUi.getChildByName("layout").active = false;
      }
      this.setCiTiaoContent(r, a, t.count);
    } else {
      this.tipUi.active = false;
      this.endindex = -1;
    }
  };
  _creator.prototype.showSetting = function () {
    UIManager.default.open(BundleConfig.BundleNames.Home, UIConfig_Home.UIView_Home.UI_Setting);
  };
  _creator.prototype.setCiTiaoContent = function (e, t) {
    var o = t.citiaomiaoshu;
    var n = Excel.Excel.shuiguobuff(t.citiaoshuzhitype);
    var i = (o = CommonUtils.default.replaceSymbols(o, "n", [""])).split("X");
    var a = "";
    for (var r = 0; r < i.length; r++) {
      var c = i[r];
      if (n.value[r] && r < i.length - 1) {
        a += "<color=#ffffff>" + c + "</c><color=#00ff00>" + n.value[r] + "</color>";
      } else {
        a += "<color=#ffffff>" + c + "</c>";
      }
    }
    a = "<outline color=#000000 width = 3>" + a + "</outline>";
    e.string = a;
  };
  _creator.prototype.onDisable = function () { };
  _creator.prototype.onJixu = function () {
    this.nowBack(3);
    this._close();
  };
  _creator.prototype.backHome = function () {
    this.tipView.active = true;
  };
  _creator.prototype.realHome = function () {
    this._close();
    this.nowBack(2);
  };
  _creator.prototype.closeHome = function () {
    this._close();
    this.tipView.active = false;
  };
  __decorate([_property(cc.Node)], _creator.prototype, "tipView", undefined);
  __decorate([_property(cc.ScrollView)], _creator.prototype, "scroll", undefined);
  __decorate([_property(cc.Node)], _creator.prototype, "tipUi", undefined);
  return __decorate([_ccclass], _creator);
}(UIView.default);
exports.default = _def_UI_GamePuase;